<?php

/**
 * @author Martin Pernica
 * @copyright 2009
 */

class VInstallater
{

    public static function StoreAdminAcc($name, $pass)
    {
        $_SESSION['adminAcc']['user'] = $name;
        $_SESSION['adminAcc']['pass'] = $pass;
    }

    public static function CheckAdminPass($str, $str2)
    {
        if ($str == $str2) {
            return true;
        } else {
            false;
        }
    }

    public static function AddLogMessage($step, $bool)
    {
        $_SESSION['log'][$step] = $bool;
    }

    public static function ExuteSql($sql, $type = "file")
    {
        if ($type == "file") {
            $str_buffer = file_get_contents($sql);
        } elseif ($type == "text") {
            $str_buffer = $sql;
        }

        $str_buffer = str_replace("{prefix}", $_SESSION['mysql']['prefix'], $str_buffer);

        $conn = mysqli_connect($_SESSION['mysql']['host'], $_SESSION['mysql']['user'], $_SESSION['mysql']['pass'],
            $_SESSION['mysql']['db']);

        $conn->query("SET NAMES utf8");

        $install = $conn->multi_query($str_buffer);

        return $install;
    }

    public static function TestSqlSetting($user, $pass, $db, $host)
    {
        if (@mysqli_connect($host, $user, $pass, $db)) {
            return true;
        } else {
            return false;
        }
    }

    public static function TestFtpSetting($user, $pass, $host)
    {
        $link = ftp_connect($host);
        return ftp_login($link, $user, $pass);
    }

    public static function PrintButton($type)
    {
        switch ($type) {
            case 'right':
                return '<input type="image" onclick="$(\'MainForm\').submit();" class="right" id="right-button" src="images/right.png" onmouseover="this.src = \'images/right_hover.png\'" onmouseout="this.src = \'images/right.png\'" />';
                break;

            case 'right-inactive':
                return '<input type="image" class="right" src="images/right_inactive.png" disabled="disabled" />';
                break;

            case 'left':
                return '<input type="image" class="right" id="left-button" src="images/left.png" onmouseover="this.src = \'images/left_hover.png\'" onmouseout="this.src = \'images/left.png\'" onclick="javascript:window.location.href=\'index.php?p=' . (intval
                    ($_GET['p']) - 1) . '\';" />';
                break;

            case 'left-inactive':
                return '<input type="image" class="right" src="images/left_inactive.png" disabled="disabled" />';
                break;

            case 'cancel':
                return '<input type="image" id="cancel" src="images/cancel.png" onmouseover="this.src = \'images/cancel_hover.png\'" onmouseout="this.src = \'images/cancel.png\'" />';
                break;

            case 'cancel-inactive':
                return '<input type="image" id="cancel" src="images/cancel.png" disabled="disabled" />';
                break;

            case 'agree':
                return '<input type="image" id="agree" src="images/agree.png" onmouseover="this.src = \'images/agree_hover.png\'" onmouseout="this.src = \'images/agree.png\'" />';
                break;

            case 'disagree':
                return '<input type="image" id="disagree" src="images/disagree.png" onmouseover="this.src = \'images/disagree_hover.png\'" onmouseout="this.src = \'images/disagree.png\'" />';
                break;

            case 'close':
                return '<input type="image" class="button" id="close-button" src="images/close.png" onmouseover="this.src = \'images/close_hover.png\'" onmouseout="this.src = \'images/close.png\'" />';
                break;

            case 'start':
                return '<input type="image" class="button" id="start-button" src="images/start.png" onmouseover="this.src = \'images/start_hover.png\'" onmouseout="this.src = \'images/start.png\'" />';
                break;

        }
    }

}

?>
